//
//  HHMainController.swift
//  weibo
//
//  Created by luwentao on 16/7/11.
//  Copyright © 2016年 luwentao. All rights reserved.
//

import UIKit

class HHMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        
        //自定义tabBar
        let tabBar = HHTabBar()
        
        //添加到默认Tabbar中,不能用self这样添加,是一个只读属性,所以要以Kvc的方式去添加
//        self.tabBar = tabBar
        setValue(tabBar, forKey: "tabBar")
        
        
        
        //主页
        addChildViewController(HHHomeController(), title: "主页", imageName: "tabbar_home")
        //消息
        addChildViewController(HHMessageController(), title: "消息", imageName: "tabbar_message_center")
        //发现
        addChildViewController(HHDiscoverController(), title: "发现", imageName: "tabbar_discover")
        //我的
        addChildViewController(HHMeController(), title: "我的", imageName: "tabbar_profile")
        
        
        

    }

    
    
    
    
    
    
    
    
    func addChildViewController(childController: UIViewController, title: String, imageName: String) {
        //设置文字,顶部和底部的都一起设置,因为是一样的,但是如果不一样就不能这样设置
        childController.title = title
        
        //正常状态下的图片
        childController.tabBarItem.image = UIImage(named: imageName)
        //选中状态下的图片,记得改渲染模式
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
        
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
        
        
        
        
    }
    
    
    
    
    
  

}
